home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <X11/Intrinsic.h>
- #include <gl.h>
- #include "data.h"
- #include <gl/sphere.h>
- #include <X11/Xirisw/GlxMDraw.h>
-
- #define SPH_DEPTH_HI 8
- #define SPH_DEPTH_LO 4
-
- extern void start_rtn(), rtn(), end_rtn(),
- start_approach(), approach(), end_approach();
-
- static char *molTranslations = "#override\n\
- <Btn1Down>:start_rtn() \n\
- <Btn1Motion>:rtn() \n\
- <Btn1Up>:end_rtn() \n\
- ";
-
- static XtActionsRec actionsTable[] = {
- {"start_rtn", start_rtn},
- {"rtn", rtn},
- {"end_rtn", end_rtn},
- {"start_approach", start_approach},
- {"approach", approach},
- {"end_approach", end_approach},
- };
-
- int prevx, prevy;
- Coord prevz, zoom = 0.0;
-
- Angle xRot = 0, yRot = 0;
- int drawAxis = FALSE;
- struct element *elementRoot = NULL;
- struct molecule *moleculeRoot = NULL;
-
- Matrix Identity = {
- 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1 };
-
- static float stuff[] = {
- SPECULAR, .72, .8, .93,
- SHININESS, 60,
- LMNULL };
-
- static float myLight[] = {
- POSITION, 0, .5, 1, 0,
- LMNULL };
-
- static float myModel[] = {
- LMNULL };
-
- extern void drawScene();
-
- /* GL widget creation code */
- #define DOUBLEBUFFER TRUE
-
- extern Widget molw;
- extern XtAppContext app_context;
-
- /* define the state for the GL widget */
- static GLXconfig glxConfig [] = {
- { GLX_NORMAL, GLX_DOUBLE, TRUE },
- { GLX_NORMAL, GLX_RGB, TRUE },
- { GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG },
- { 0, 0, 0 }
- };
-
- extern XtCallbackProc
- initCB(),
- exposeCB(),
- resizeCB();
-
-
- Widget
- create_mol_widget(parent)
- Widget parent;
- {
- Widget w;
- Arg args[5];
- int n = 0;
- XtTranslations trans = XtParseTranslationTable(molTranslations);
-
- XtAppAddActions(app_context, actionsTable, XtNumber(actionsTable));
-
- /* define the GL state of the window */
- XtSetArg(args[n], GlxNglxConfig, glxConfig); n++;
-
- /* create the widget */
- w = XtCreateWidget("mol", glxMDrawWidgetClass, parent, args, n);
-
- /* add the callbacks */
- XtAddCallback(w, GlxNginitCallback, initCB, NULL);
- XtAddCallback(w, GlxNexposeCallback, exposeCB, NULL);
- XtAddCallback(w, GlxNresizeCallback, resizeCB, NULL);
-
- XtOverrideTranslations(w, trans);
- XtManageChild(w);
-
- return w;
- }
-
-
- XtCallbackProc
- initCB(w, client, call)
- Widget w;
- caddr_t call;
- caddr_t client;
- {
- /* Mixed-model equivalent to winset() */
- GLXwinset(XtDisplay(w), XtWindow(w));
-
- if (DOUBLEBUFFER)
- doublebuffer();
- zbuffer(TRUE);
- RGBmode();
- backface(TRUE);
-
- czclear(0x404040, getgdesc(GD_ZMAX));
- if (DOUBLEBUFFER) {
- swapbuffers();
- czclear(0x404040, getgdesc(GD_ZMAX));
- }
-
- mmode(MVIEWING);
- loadmatrix(Identity);
- perspective(600, 5.0/4.0, .25, 15.0);
- translate(0, 0, -4);
- lmdef(DEFMATERIAL, 1, 0, stuff);
- lmdef(DEFLIGHT, 1, 0, myLight);
- lmdef(DEFLMODEL, 1, 0, myModel);
-
- lmbind(MATERIAL, 1);
- lmbind(LMODEL, 1);
- lmbind(LIGHT0, 1);
-
- sphmode(SPH_DEPTH, SPH_DEPTH_HI);
- sphmode(SPH_HEMI, TRUE);
- sphmode(SPH_ORIENT, TRUE);
-
- }
-
- XtCallbackProc
- exposeCB(w, client, call)
- Widget w;
- caddr_t call;
- caddr_t client;
- {
- GLXwinset(XtDisplay(w), XtWindow(w));
-
- /* draw the scene */
- drawScene();
-
- }
-
- XtCallbackProc
- resizeCB(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- GlxDrawCallbackStruct *call_data;
- {
- GLXwinset(XtDisplay(w), XtWindow(w));
-
- /* use the new size provided by the ResizeEvent */
- viewport(0, (Screencoord) call_data->width-1,
- 0, (Screencoord) call_data->height-1);
-
- /* draw the scene at the new size */
- drawScene();
- }
-
- void doAxis() {
- static float origin[] = {0, 0, 0};
- static float x[] = {100, 0, 0};
- static float y[] = {0, 100, 0};
- static float z[] = {0, 0, 100};
-
- cpack(0x0000ff);
- bgnline();
- v3f(origin);
- v3f(x);
- endline();
-
- cpack(0x00ff00);
- bgnline();
- v3f(origin);
- v3f(y);
- endline();
-
- cpack(0xff0000);
- bgnline();
- v3f(origin);
- v3f(z);
- endline();
- }
-
- void drawMolecule(struct molecule *m) {
- struct atom* atoms;
- float xsize, ysize, zsize, maxdim;
- float v[4];
-
- if (!m)
- return;
- xsize = (m->max[0] - m->min[0]);
- ysize = (m->max[1] - m->min[1]);
- zsize = (m->max[2] - m->min[2]);
- maxdim = MAX(MAX(xsize, ysize), zsize);
-
- pushmatrix();
- lmcolor(LMC_AD);
- scale(3/maxdim, 3/maxdim, 3/maxdim);
- translate(-(m->min[0]+xsize/2),
- -(m->min[1]+ysize/2),
- -(m->min[2]+zsize/2));
- atoms = m->atoms;
- while(atoms) {
- v[0] = atoms->xyz[0]; v[1] = atoms->xyz[1]; v[2] = atoms->xyz[2];
- v[3] = atoms->e->radius;
- cpack(atoms->e->color);
- sphdraw(v);
- atoms = atoms->next;
- }
- popmatrix();
- lmcolor(LMC_COLOR);
- }
-
- void drawScene() {
- pushmatrix();
- czclear(0x404040, getgdesc(GD_ZMAX));
-
- /* translate(0, 0, zoom);*/
- rotate(xRot, 'x');
- rotate(yRot, 'y');
- drawMolecule(moleculeRoot);
- if (drawAxis)
- doAxis();
-
- if (DOUBLEBUFFER)
- swapbuffers();
- popmatrix();
- }
-
- void
- start_rtn(w, event)
- Widget w;
- XEvent *event;
- {
- /* go to low-res display */
- sphmode(SPH_DEPTH, SPH_DEPTH_LO); /**/
- prevx = event->xbutton.x;
- prevy = event->xbutton.y;
- }
-
- void
- rtn(w, event)
- Widget w;
- XEvent *event;
- {
- int x = event->xbutton.x;
- int y = event->xbutton.y;
-
- yRot += (Angle) 5 * (x - prevx);
- xRot += (Angle) 5 * (y - prevy);
- prevx = x;
- prevy = y;
- drawScene();
- }
-
- void
- end_rtn(w, event)
- Widget w;
- XEvent *event;
- {
- /* go back to hi-res display */
- sphmode(SPH_DEPTH, SPH_DEPTH_HI); /**/
- drawScene();
- }
-
-
- void start_approach(w, event)
- Widget w;
- XEvent *event;
- {
- /* go to low-res display */
- sphmode(SPH_DEPTH, SPH_DEPTH_LO); /**/
- prevz = (Coord) event->xbutton.y;
- }
-
- void approach(w, event)
- Widget w;
- XEvent *event;
- {
- int y = event->xbutton.y;
-
- zoom += (Coord) (5 * (prevz - y))/100.0;
- prevz = y;
- drawScene();
- }
-
- void end_approach(w, event)
- Widget w;
- XEvent *event;
- {
- /* go back to hi-res display */
- sphmode(SPH_DEPTH, SPH_DEPTH_HI); /**/
- drawScene();
- }
-
- void dokeyboard(){}
-